package com.goldmantis.alitrip.service;

import com.goldmantis.alitrip.common.BaseService;
import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.*;
import com.taobao.api.response.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author:Shmily
 * @Description:
 * @Date:Create in 17:44 2018/1/15
 */
@Service
public class CostCenterService extends BaseService {

    @Autowired
    private  TaobaoClient client;


    public AlitripBtripCostCenterGetResponse getCostCenterByUserId(String userId) throws Exception {

        AlitripBtripCostCenterGetRequest req = new AlitripBtripCostCenterGetRequest();
        req.setCorpId(corp_id);
        req.setUserId(userId);

        AlitripBtripCostCenterGetResponse rsp = client.execute(req, accessToken);
        return rsp;
    }

    /*
    根据条件获取成本中心
     */
    public AlitripBtipCostCenterQueryResponse getCostCenterByQuery(AlitripBtipCostCenterQueryRequest.OpenCostCenterQueryRq openCostCenterQueryRq) throws Exception {
        openCostCenterQueryRq.setCorpId(corp_id);
        openCostCenterQueryRq.setUserId("0442165202482222255"); //系统管理员
        AlitripBtipCostCenterQueryRequest req = new AlitripBtipCostCenterQueryRequest();
        req.setRq(openCostCenterQueryRq);
        AlitripBtipCostCenterQueryResponse rsp = client.execute(req, accessToken);
        return rsp;
    }

    public AlitripBtripCostCenterNewResponse insert(AlitripBtripCostCenterNewRequest.OpenCostCenterSaveRq openCostCenterSaveRq) throws Exception {
        AlitripBtripCostCenterNewRequest req = new AlitripBtripCostCenterNewRequest();
        openCostCenterSaveRq.setCorpId(corp_id);
        req.setRq(openCostCenterSaveRq);
        AlitripBtripCostCenterNewResponse rsp = client.execute(req, accessToken);
        return rsp;
    }

    public AlitripBtripCostCenterModifyResponse update(AlitripBtripCostCenterModifyRequest.OpenCostCenterModifyRq openCostCenterModifyRq) throws Exception {
        AlitripBtripCostCenterModifyRequest req = new AlitripBtripCostCenterModifyRequest();
        openCostCenterModifyRq.setCorpId(corp_id);
        req.setRq(openCostCenterModifyRq);
        AlitripBtripCostCenterModifyResponse rsp = client.execute(req, accessToken);
        return rsp;
    }

    /**
     *
     * @param thirdpart_id 第三方成本中心Id
     * @return 删除结果
     * @throws Exception
     */
    public AlitripBtripCostCenterDeleteResponse delete(String thirdpart_id) throws Exception {
        AlitripBtripCostCenterDeleteRequest req = new AlitripBtripCostCenterDeleteRequest();
        AlitripBtripCostCenterDeleteRequest.OpenCostCenterDeleteRq openCostCenterDeleteRq = new AlitripBtripCostCenterDeleteRequest.OpenCostCenterDeleteRq();
        openCostCenterDeleteRq.setThirdpartId(thirdpart_id);
        openCostCenterDeleteRq.setCorpId(corp_id);
        req.setRq(openCostCenterDeleteRq);
        AlitripBtripCostCenterDeleteResponse rsp = client.execute(req, accessToken);
        return rsp;
    }
}
